package com.woniu.cms.goods.core.controller;


import com.woniu.cms.goods.core.dto.SettleDto;
import com.woniu.cms.goods.core.entity.GoodsReturn;
import com.woniu.cms.goods.core.entity.GoodsReturnMaterial;
import com.woniu.cms.goods.core.entity.GoodsSettle;
import com.woniu.cms.goods.core.entity.GoodsSettleMaterial;
import com.woniu.cms.goods.core.service.IGoodsSettleService;
import com.woniu.common.api.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author romantic sheep
 * @since 2022-09-19
 */
@RestController
@Api(tags = "结算单")
@RequestMapping("/goods-settle")
public class GoodsSettleController {

    @Autowired
    private IGoodsSettleService settleService;

    /*
     * 查询所有结算单
     * @currentPage，当前页码
     * @pageSize，页面大小
     * @status，退料单状态
     * */
    @GetMapping
    @ApiOperation("分页/按状态查询结算单")
    public Result getlist(Integer currentPage, Integer pageSize, Integer status){
        Result result = settleService.getlist(currentPage,pageSize,status);
        return result;
    }
    /*
     * 新增结算单
     * @goodsReturn，结算单主表信息
     * @list，结算单材料明细页材料列表
     * */
    @ApiOperation("新增结算单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "settleDto",value = "结算单主表信息,结算单材料明细页材料列表")
    })
    @PostMapping("insert")
    public Result addSettle(@RequestBody SettleDto settleDto){
        GoodsSettle goodsSettle = settleDto.getGoodsSettle();
        List<GoodsSettleMaterial> list = settleDto.getList();
        Result result = settleService.addSettle(goodsSettle,list);
        return result;
    }
    /*
     * 删除结算单
     * @id，结算单主表id
     * @status，提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）
     * */
    @ApiOperation("删除结算单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "结算单主表id"),
            @ApiImplicitParam(name = "status",value = "提交状态（0-未提交，1-已提交（审批中），2-审批通过，3-已驳回）")
    })
    @DeleteMapping("delete")
    public Result deleteSettle(Integer id,Integer status){
        Result result=settleService.deleteSettle(id,status);
        return result;
    }
    /*
     * 修改结算单
     * @goodsReturn，结算单主表信息
     * @list，结算单材料明细页材料列表
     * */
    @ApiOperation("修改结算单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "settleDto",value = "结算单主表信息,结算单材料明细页材料列表")
    })
    @PutMapping("update")
    public Result updateSettle(@RequestBody SettleDto settleDto){
        GoodsSettle goodsSettle = settleDto.getGoodsSettle();
        List<GoodsSettleMaterial> list = settleDto.getList();
        Result result=settleService.updateSettle(goodsSettle,list);
        return result;
    }
    /*
     * 提交结算单
     * @goodsReturn，结算单主表信息
     * @list，结算单材料明细页材料列表
     * */
    @ApiOperation("提交结算单")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "settleDto",value = "结算单主表信息,结算单材料明细页材料列表")
    })
    @PutMapping("commit")
    public Result commitSettle(@RequestBody SettleDto settleDto){
        GoodsSettle goodsSettle = settleDto.getGoodsSettle();
        List<GoodsSettleMaterial> list = settleDto.getList();
        Result result=settleService.commitSettle(goodsSettle,list);
        return result;
    }



}

